package com.cxhc.web.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cxhc.system.domain.app.Tree;
import com.cxhc.system.service.app.ITreeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cxhc.common.annotation.Log;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.enums.BusinessType;
import com.cxhc.common.core.page.TableDataInfo;

/**
 * 树木Controller
 * 
 * @author Dhq
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/admin/tree")
public class TreeController extends BaseController
{
    @Autowired
    private ITreeService treeService;

    /**
     * 查询树木列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Tree tree)
    {
        startPage();
        List<Tree> list = treeService.selectTreeList(tree);
        return getDataTable(list);
    }

    /**
     * 获取树木详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(treeService.selectTreeById(id));
    }

    /**
     * 新增树木
     */
    @Log(title = "树木", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tree tree)
    {
        return toAjax(treeService.insertTree(tree));
    }

    /**
     * 修改树木
     */
    @Log(title = "树木", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tree tree)
    {
        return toAjax(treeService.updateTree(tree));
    }

    /**
     * 删除树木
     */
    @Log(title = "树木", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(treeService.deleteTreeByIds(ids));
    }
}
